package com.tobearc.persist.server;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

/**
 * 
 * @author yangqifan
 */
public class SocketServer implements IServer {

	public boolean init() {
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
		
		chain.addLast("code", new ServerCodec());
		chain.addLast("handler", null);
		return false;
	}

	public boolean start() {
		return false;
	}

	public boolean stop() {
		return false;
	}

	static class ServerCodec extends ProtocolCodecFilter{
		private static Decoder decoder = new Decoder();
		private static Encoder encoder = new Encoder();

		public ServerCodec() {
			super(encoder, decoder);
		}
		
	}
	
	static class Decoder implements ProtocolDecoder{

		public void decode(IoSession session, IoBuffer in,
				ProtocolDecoderOutput out) throws Exception {
			
		}

		public void finishDecode(IoSession session, ProtocolDecoderOutput out)
				throws Exception {
			
		}

		public void dispose(IoSession session) throws Exception {
			
		}

		
	}
	
	static class Encoder implements ProtocolEncoder{

		public void encode(IoSession session, Object message,
				ProtocolEncoderOutput out) throws Exception {
			
		}

		public void dispose(IoSession session) throws Exception {
			
		}
		
	}
}
